package com.woniu.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniu.project.core.dto.ResultDto;
import com.woniu.project.dto.shopdto.ShopDto;
import com.woniu.project.params.shopparams.ShopConditionParams;
import com.woniu.project.params.shopparams.ShopParams;
import com.woniu.project.service.IShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author WHF
 * @since 2020-10-12
 */
@RestController
@RequestMapping("/shop")
@Slf4j
@Api(tags = "shop控制层")
public class ShopController {

    @Autowired
    private IShopService shopService;

    /**
     * 分页查询所有门店信息
     * @param shopParams 查询条件对象
     * @return
     */
    @ApiOperation(value = "查询门店列表",notes = "必填项无")
    @GetMapping("/selectShop")
    public ResultDto selectShop(ShopConditionParams shopParams){
        log.info("查询门店时传入的参数对象为：{}",shopParams);
        IPage<ShopDto> shopDtoIPage = shopService.pageQuery(shopParams);
        return ResultDto.success(shopDtoIPage);
    }

    /**
     * 根据门店id查询单个门店信息
     * @param shopId 门店id
     * @return
     */
    @ApiOperation(value = "查询单个门店详情",notes = "无")
    @GetMapping("/selectOneShop/{shopId}")
    public ResultDto selectOneShop(@PathVariable("shopId") int shopId){
        log.info("查询单个门店时传入的门店id为：{}",shopId);
        ShopDto shopDto = shopService.selectOneShop(shopId);
        return ResultDto.success(shopDto);
    }

    /**
     * 新增/修改门店
     * @param shopParams 门店对象
     * @return
     */
    @ApiOperation(value = "新增/修改门店",notes = "必填项无")
    @PostMapping("updateShop")
    public ResultDto updateShop(@RequestBody ShopParams shopParams){
        shopService.updateShop(shopParams);
        return ResultDto.success(200,"新增/修改成功",null);
    }

    /**
     * 根据门店id删除门店
     * @param shopId 门店id
     * @return
     */
    @ApiOperation(value = "删除门店",notes = "无")
    @DeleteMapping("/deleteOneShop/{shopId}")
    public ResultDto deleteOneShop(@PathVariable("shopId") int shopId){
        log.info("要删除单个门店时传入的门店id为：{}",shopId);
        shopService.deleteOneShop(shopId);
        return ResultDto.success(200,"删除成功",null);
    }

}

